package tests.function;

import common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.io.IOException;

import static java.lang.Thread.sleep;

/**
 * Created with IntelliJ IDEA.
 * Description: 注册功能测试
 * User: Spider-Man
 * Date: 2025-09-21
 * Time: 14:26
 */
public class RegisterFunction {
    public static final String url = "http://43.143.179.59:8080/blogin.html";
    public static final String registerUrl = "http://43.143.179.59:8080/register.html";
    public static final String title = "注册页面";


    /**
     * 注册一个管理员用户
     * 姓名: 孙悟空
     * 邮箱:124@qq.com
     * 手机号:14511111111
     * 密码: 111111
     */
    public void registerAdmin() throws IOException, InterruptedException {
        WebDriver driver = Utils.createDriver();
        driver.get(url);
        driver.findElement(By.cssSelector("body > div > div.login-container.col-sm-6.col-md-6.col-lg-5.col-xl-5 > div.register-link > a")).click();//点击注册,进行页面跳转
        String expect = driver.getCurrentUrl();
        assert expect.equals(registerUrl): "页面未跳转到连接: http://43.143.179.59:8080/register.html";
        expect = driver.getTitle();
        assert expect.equals(title) : "页面标题错误";
        driver.findElement(By.cssSelector("#name")).sendKeys("孙悟空");
        Thread.sleep(1);
        driver.findElement(By.cssSelector("#mail")).sendKeys("124@qq.com");
        driver.findElement(By.cssSelector("#phoneNumber")).sendKeys("14511111111");
        driver.findElement(By.cssSelector("#password")).sendKeys("111111");
        driver.findElement(By.cssSelector("#registerForm > button")).click();
        Utils.getScreenShot(Thread.currentThread().getName());
        //注册成功出现弹窗
        Alert alert = driver.switchTo().alert();
        alert.accept();
        //跳转到登录页面
        expect = driver.getCurrentUrl();
        assert expect.equals(url);
        Utils.getScreenShot(Thread.currentThread().getName());
    }
}
